<?
/**
 * GDataGridColumn
 */
class GDataGridColumn{
	public $dataField;
	public $text;
	public $class;
	public $format;
	public $feature=false;
	public $align="left";
	public $wrapping="nowrap";
	public $width=NULL;
	public $ahref=NULL,$atarget=NULL,$aclass=NULL,$aid=NULL,$ajs=NULL;

	public function __construct($dataField=NULL,$text=NULL,$class=NULL,$feature=NULL,$format=NULL){
		$this->setDataField($dataField);
		$this->setText($text);
		$this->setClass($class);
		$this->setFeature($feature);
		$this->setFormat($format);
	}

	public function getDataFieldHtml($row){
		$result="";
		if($this->ahref!==NULL){
			$result.='<a href="'.$this->ahref.'"';
			if($this->atarget!==NULL){
				$result.=' target="'.$this->atarget.'"';
			}
			if($this->aclass!==NULL){
				$result.=' class="'.$this->aclass.'"';
			}
			if($this->aid!==NULL){
				$result.=' id="'.$this->aid.'"';
			}
			if($this->ajs!==NULL){
				$result.=" $this->ajs";
			}
			$result.='>';
		}
		$value=$row[$this->getDataField()];
		
		if($format=$this->getFormat()){
			$format->setValue($value);
			$value=$format->getValue();
		}
		$result.=$value;
		if($this->ahref!==NULL){
			$result.='</a>';
		}
		return($result);
	}
	public function getDataField(){
		return($this->dataField);
	}
	public function setDataField($dataField){
		if($dataField!==NULL){
			$this->dataField=$dataField;
		}
	}

	public function getFormat(){
		return($this->format);
	}
	public function setFormat($value){
		if($value!==NULL){
			$this->format=$value;
			$this->setAlign($value->getAlign());
		}
	}

	public function getText(){
		$text=$this->text;
		if(is_object($text)){
			$text=$text->toHtml();
		}
		return($text);
	}
	public function setText($text=NULL){
		$tmp=$this->getDataField();
		if($text===NULL&&$tmp!==NULL){
			if(preg_match_all('/((?:^|[A-Z])[a-z]+)/',$tmp,$matches)){
				$tmp=$matches[1];
			}
			$text=formatter::TCase(join(" ",$tmp));
		}
		$this->text=$text;
	}

	public function getClass(){
		return($this->class);
	}
	public function setClass($class){
		$tmp=$this->getDataField();
		if($class===NULL&&$tmp!==NULL){
			$this->class=strtolower($tmp);
		}
		$this->class=$class;
	}

	public function getFeature(){
		return($this->feature);
	}
	public function setFeature($feature){
		$this->feature=($feature===TRUE||$feature>0);
	}

	public function getAlign(){
		return($this->align);
	}
	public function setAlign($align=NULL){
		$this->align=($align===NULL)?"left":$align;
	}

	public function getWrappingHtml(){
		return(($this->wrapping=="nowrap")?' nowrap="nowrap"':"");
	}
	public function setWrapping($wrapping=NULL){
		$this->wrapping=($wrapping===NULL)?"nowrap":$wrapping;
	}

	public function getWidthHtml(){
		$width=$this->getWidth();
		return(($width===NULL)?'':' width="'.$width.'"');
	}
	public function getWidth(){
		return($this->width);
	}
	public function setWidth($width=NULL){
		$this->width=$width;
	}

	public function setLink($href,$target=NULL,$class=NULL,$id=NULL,$js=NULL){
		$this->ahref=$href;
		$this->atarget=$target;
		$this->aclass=$class;
		$this->aid=$id;
		$this->ajs=$js;
	}
};
?>
